﻿
package com.victim.snake.room
{
	import flash.utils.Dictionary;
	import com.victim.snake.player.Player;

	//玩家队伍类
	public class Group{
		public var groupId:int=0;	//队标,对应到每个房间的队伍数组中(1为给队，2为绿队，3为橙队，4为紫队)
		public var players:Dictionary=new Dictionary();	//用户
		public var foodCounter:int=0;	//食物计数器
		public var deathCounter:int=0;	//死亡计数器
		
		/**
		 * 构造函数
		 * @param groupId	队标,对应到每个房间的队伍数组中(0为红队，1为绿队，2为橙队，3为紫队)
		 */
		public function Group(groupId:int):void{
			this.groupId=groupId;
		}
		
		/**
		 * @return	队伍人数
		 */
		public function getPlayersCount():int{
			var i:int=0;
			for each(var o:Object in players){
				i++;
			}
			return i;
		}
		
		/**
		 * 食物计数器加1
		 * @return
		 */
		public function addFoodCounter():int{
			return ++this.foodCounter;
		}
		
		/**
		 * 死亡计数器加1
		 * @return
	 	*/
		public function addDeathCounter():int{
			return ++this.deathCounter;
		}
		
		/**
		 * 按id取得用户
		 * @param i
		 * @return
		 */
		public function getPlayerById(i:int):Player{
			return players[i];
		}
		
		
		/**
		 * 添加用户到队伍里
		 * @param ut
		 */
		public function addPlayer(player:Player):void{
			players[player.getUid()]=player;
			player.setGroup(this);
		}
		
		/**
		 * 从队伍中移除用户
	 	* @param ut
		 */
		public function removePlayer(player:Player){
			for (var o:Object in players){
				if(players[o]==player){
					delete players[o];
					player.setGroup(null);
					return;
				}
			}
		}
		
		
		
	}
}